/**
 * @description  : wechat 平台提供的集合类的api适配
 * @descriptionDetail :
 * @copyright    : 内蒙
 * @author       : fsx
 * @create       : 2023-09-04 19:33:31
 */
import {
	pathToBase64
} from "image-tools";
import * as EXIF from "exif-js";
import {
	DD_MODEL
} from "@/config/setting.config.js";
// 企业微信 android 与 ios 存在差异 请勿删除此处代码 start fsx
let WX;
if (wx.config == undefined) {
	WX = jWeixin;
} else {
	WX = wx;
}
// 企业微信 android 与 ios 存在差异 请勿删除此处代码 end fsx

let WeChat = {
	/**
	 * 企微鉴权
	 * @param {*} resData
	 * @returns
	 */
	wxLogin(agentId, token) {
		return new Promise((resolve, reject) => {
			if (!agentId && !token) {
				reject("缺失agentId或者免登陆授权码");
			}

			anyPortal.ready({
					appId: agentId,
					jsApiList: [
						"checkJsApi",
						"onMenuShareAppMessage",
						"onMenuShareWechat",
						"onMenuShareTimeline",
						"shareAppMessage",
						"shareWechatMessage",
						"startRecord",
						"stopRecord",
						"onVoiceRecordEnd",
						"playVoice",
						"pauseVoice",
						"stopVoice",
						"uploadVoice",
						"downloadVoice",
						"chooseImage",
						"previewImage",
						"uploadImage",
						"downloadImage",
						"getNetworkType",
						"openLocation",
						"getLocation",
						"hideOptionMenu",
						"showOptionMenu",
						"hideMenuItems",
						"showMenuItems",
						"hideAllNonBaseMenuItem",
						"showAllNonBaseMenuItem",
						"closeWindow",
						"scanQRCode",
						"previewFile",
						"openEnterpriseChat",
						"selectEnterpriseContact",
						"onHistoryBack",
						"openDefaultBrowser",
					],
				},
				function() {
					console.log("token", token);
					// 获取用户信息
					anyPortal.getAccountInfo(token, {
						onSuccess: function(userInfo) {
							// if (Number(userInfo.code) === 996) {
							// 	// 选择用户
							// 	anyPortal.saveAppAccountRel({
							// 		thirdPartyUuid: userInfo.msg,
							// 		accountUuid: userInfo.data[0].accountUuid,
							// 	}, {
							// 		onSuccess: function(info) {
							// 			console.log('info', info)
							// 		},
							// 		onFail: function(e) {
							// 			console.log('e', e)
							// 		},
							// 	})
							// } else {
							console.log("userInfo------", userInfo);
							resolve(userInfo);
							// }
						},
						onFail: (err) => {
							console.log("err", err);
							alert(err);
						},
					});
				}
			);
		});
	},

	/**
	 * 隐藏头部菜单
	 * @returns
	 */
	hideOptionMenu() {
		if (DD_MODEL === 0) {
			WX.hideMenuItems({
				menuList: [],
			});
		} else {
			WX.showMenuItems({
				menuList: [
					"menuItem:setFont",
					"menuItem:refresh",
					"menuItem:FloatWindow",
					"menuItem:share:appMessage",
					"menuItem:share:wechat",
					"menuItem:share:wechat circle",
					"menuItem:favorite",
					"menuItem:copyUrl",
					"menuItem:openWithSafari",
					"menuItem:share:email",
				],
			});
		}
		// WX.showMenuItems({
		// 	menuList: [
		// 		'menuItem:setFont',
		// 		'menuItem:refresh',
		// 		'menuItem:share:appMessage',
		// 		'menuItem:share:wechat',
		// 		'menuItem:favorite',
		// 		'menuItem:copyUrl',
		// 		'menuItem:openWithSafari',
		// 		'menuItem:share:email'
		// 	]
		// })
	},

	setTitle(tit) {
		document.title = tit;
	},

	/**
	 * 获取设备信息
	 * @returns Promise
	 */
	device() {
		return new Promise((resolve, reject) => {
			uni.getSystemInfo({
				success: function(res) {
					let data = {
						brand: res.brand,
						model: res.model,
						pixelRatio: res.pixelRatio,
						screenWidth: res.screenWidth,
						screenHeight: res.screenHeight,
						system: res.system,
						platform: res.platform,
					};
					resolve(data);
				},
				fail(e) {
					reject(e);
				},
			});
		});
	},

	/**
	 * 获取当前的地理位置、速度
	 * @param {Object} type  wgs84返回gps 坐标，gcj02返回国测局坐标
	 */
	geolocation(type) {
		return new Promise(function(resolve, reject) {
			WX.getLocation({
				type: "gcj02", // 默认为wgs84的gps坐标，如果要返回直接给openLocation用的火星坐标，可传入'gcj02'
				success: function(res) {
					resolve(res);
				},
				fail(err) {
					reject(err);
				},
			});
		});
	},

	/**
	 *  打开地图选择位置
	 * @param {Object} latitude
	 * @param {Object} longitude
	 */
	chooseLocation(latitude, longitude) {
		return new Promise(function(resolve, reject) {
			uni.chooseLocation({
				success: function(res) {
					resolve(res);
				},
				fail(e) {
					reject(e);
				},
			});
		});
	},

	/**
	 * 使用应用内置地图查看位置
	 * @param {Object} latitude
	 * @param {Object} longitude
	 */
	openLocation(latitude, longitude) {
		return new Promise(function(resolve, reject) {
			WX.openLocation({
				latitude: Float(latitude),
				longitude: Float(longitude),
				scale: 24,
				success: function() {
					resolve(true);
				},
				fail() {
					reject(false);
				},
			});
		});
	},

	/**
	 * 打开指定位置
	 * @param {*} latitude     	纬度
	 * @param {*} longitude   	经度
	 * @param {*} address   		地址/POI名称
	 */
	navigateMap(latitude, longitude, address, name = "", scale = 24) {
		WX.openLocation({
			latitude,
			longitude,
			name,
			address,
			scale,
		});
	},
	/**
	 * 复制到剪切板
	 * @param {*} data     	剪贴板的内容
	 */
	clipboardData(data, callback) {
		WX.setClipboardData({
			data,
			success: (result) => callback(true),
			fail: (err) => callback(false),
			cancel: (cel) => callback(false),
		});
	},

	/**
	 * 微信提示
	 * @param {*} msg     提示信息
	 * @param {*} title   标题(可选)
	 */
	alert(msg, title, success) {
		uni.showModal({
			title: title || "提示",
			content: msg,
			confirmText: "确定",
			success: function(res) {
				if (res.confirm) {
					success && success();
				}
			},
		});
	},

	/**
	 * 微信toast弹窗
	 */
	toast(str) {
		uni.showToast({
			title: str,
		});
	},

	/**
	 * 是否显示顶部的自定义导航栏  并不当做顶部导航栏是否显示，只是用作代码中的配套
	 * @returns
	 */
	isHideNav() {
		return true;
	},

	/**
	 * 客户端(apk/ipa)的版本名称
	 */
	getAppVersion() {},

	/**
	 * 客户端的版本号
	 */
	getAppVersionCode() {},

	/**
	 * 从本地相册选择图片或使用相机拍照
	 * @param {Object} maxSize 最多可以选择的图片张数，默认   1
	 */
	chooseImage(maxSize) {
		return new Promise(function(resolve, reject) {
			uni.chooseImage({
				count: maxSize ? maxSize : 1, // 默认1
				sizeType: ["original", "compressed"], // 可以指定是原图还是压缩图，默认二者都有
				sourceType: ["album", "camera"], // 从相册选择或者拍照
				success: function(res) {
					resolve(res.tempFilePaths);
				},
				fail(e) {
					reject(e);
				},
			});
		});
	},

	/**
	 * 从本地相册选择图片或使用相机拍照 获取base64
	 * @param {Object} maxSize 最多可以选择的图片张数，默认   1
	 */
	chooseImageToBase64(maxSize) {
		return new Promise(function(resolve, reject) {
			uni.chooseImage({
				count: maxSize ? maxSize : 1, // 默认1
				sizeType: ["original", "compressed"], // 可以指定是原图还是压缩图，默认二者都有
				sourceType: ["album", "camera"], // 从相册选择或者拍照
				success: function(res) {
					Promise.all(res.tempFilePaths.map((itm) => pathToBase64(itm)))
						.then((dta) => {
							resolve(dta);
						})
						.catch((err) => {
							reject(err);
						});
				},
				fail(e) {
					reject(e);
				},
			});
		});
	},

	/**
	 * 图片旋转角度
	 */
	changeImgOrientation(resImg, Orientation) {
		return new Promise((resolve, reject) => {
			let self = this;
			let img = new Image();
			img.src = resImg;
			img.onload = function() {
				let canvas = document.createElement("canvas");
				let ctx = canvas.getContext("2d");
				let imgWidth = (canvas.width = this.width);
				let imgHeight = (canvas.height = this.height);
				// 如果方向角不为1，都需要进行旋转 added by lzk
				if (Orientation && Orientation != 1) {
					switch (Orientation) {
						case 6: // 旋转90度
							canvas.width = this.height;
							canvas.height = this.width;
							ctx.rotate(Math.PI / 2);
							ctx.drawImage(this, 0, -imgHeight, imgWidth, imgHeight);
							break;
						case 3: // 旋转180度
							ctx.rotate(Math.PI);
							ctx.drawImage(this, -imgWidth, -imgHeight, imgWidth, imgHeight);
							break;
						case 8: // 旋转-90度
							canvas.width = imgHeight;
							canvas.height = imgWidth;
							ctx.rotate((3 * Math.PI) / 2);
							ctx.drawImage(this, -imgWidth, 0, imgWidth, imgHeight);
							break;
					}
				} else {
					ctx.drawImage(this, 0, 0, imgWidth, imgHeight);
				}
				let base64code = canvas.toDataURL("image/jpeg");
				resolve(base64code);
			};
		});
	},

	/**
	 * 从本地相册选择图片或使用相机拍照
	 * @param {Object} maxSize 最多可以选择的图片张数，默认   1
	 * @param {Int} sType 0 默认，1 相册 ， 2 拍照
	 * @param {Number} quality   0-1
	 * @param {Number} widthScale 0-1
	 * @param {String} enableVide 'false'
	 */
	chooseImageToCompress({
		maxSize = 1,
		sType = 0,
		quality = 0.65,
		widthScale = 1,
	}) {
		return new Promise((resolve, reject) => {
			let ar = ["album", "camera"];
			if (sType == 1) {
				ar = ["album"];
			} else if (sType == 2) {
				ar = ["camera"];
			}
			uni.chooseImage({
				count: maxSize,
				sizeType: ["original", "compressed"],
				sourceType: ar,
				success: (res1) => {
					uni.showLoading({
						title: "正在压缩图片...",
						success() {},
						mask: false,
					});
					Promise.all(
						res1.tempFilePaths.map((path) => {
							return new Promise((resolve, reject) => {
								let self = this;
								let img = new Image();
								let canvas = document.createElement("canvas");
								let ctx = canvas.getContext("2d");
								img.src = path;
								img.onload = function() {
									EXIF.getData(img, function() {
										let Orientation = EXIF.getTag(this, "Orientation");
										let make = EXIF.getTag(this, "Make");
										// IOS 13.4以上不需要进行旋转
										let getVersionRotate = () => {
											let ua = navigator.userAgent.toLowerCase();
											let ver = ua.match(/cpu iphone os (.*?) like mac os/);
											try {
												let b = ver[1].replace(/_/g, ".");
												return self.toNum(b) >= self.toNum(13.4);
											} catch (err) {
												console.log(err);
												return false;
											}
										};

										if (
											Orientation &&
											Orientation != 1 &&
											!getVersionRotate()
										) {
											// 当旋转值存在且不为1时，调用changeImgOrientation将其还原，并返回base64值
											self
												.changeImgOrientation(path, Orientation)
												.then((rxp) => {
													let imgXp = new Image();
													imgXp.src = rxp;
													imgXp.onload = function() {
														canvas.width = imgXp.width;
														canvas.height = imgXp.height;
														ctx.drawImage(img, 0, 0, imgXp.width, imgXp.height);
														let tmp = canvas.toDataURL("image/jpeg");
														let dp = {
															graphicContents: tmp.split(",")[1],
															size: null,
														};
														self.getImgByteSize(dp);
														if (dp.size >= 4 * 1024 * 1024) {
															// 大于4M
															quality = 0.5;
															widthScale = 0.6;
														} else if (
															dp.size >= 3 * 1024 * 1024 &&
															dp.size <= 1024 * 1024 * 4
														) {
															// 大于3M
															quality = 0.6;
															widthScale = 0.7;
														} else if (
															dp.size >= 1024 * 1024 &&
															dp.size < 1024 * 1024 * 3
														) {
															// 大于1M 小于3M
															quality = 0.7;
															widthScale = 0.8;
														} else {
															// 小于1M
															quality = 0.92;
															widthScale = 0.9;
														}
														if (make != "Apple") {
															widthScale = 0.7;
														}
														self
															.compressImage(
																rxp,
																path.substring(path.lastIndexOf(".") + 1),
																maxSize,
																quality,
																widthScale,
																make == "Apple"
															)
															.then((rpp) => {
																resolve(rpp);
															});
													};
												});
										} else {
											canvas.width = img.width;
											canvas.height = img.height;
											ctx.drawImage(img, 0, 0, img.width, img.height);
											let tmp = canvas.toDataURL("image/jpeg");
											let dp = {
												graphicContents: tmp.split(",")[1],
												size: null,
											};
											self.getImgByteSize(dp);
											if (dp.size >= 4 * 1024 * 1024) {
												// 大于4M
												quality = 0.5;
												widthScale = 0.6;
											} else if (
												dp.size >= 3 * 1024 * 1024 &&
												dp.size <= 1024 * 1024 * 4
											) {
												// 大于3M
												quality = 0.6;
												widthScale = 0.7;
											} else if (
												dp.size >= 1024 * 1024 &&
												dp.size < 1024 * 1024 * 3
											) {
												// 大于1M 小于3M
												quality = 0.7;
												widthScale = 0.8;
											} else {
												// 小于1M
												quality = 0.92;
												widthScale = 0.9;
											}
											if (make != "Apple") {
												widthScale = 0.7;
											}
											self
												.compressImage(
													path,
													path.substring(path.lastIndexOf(".") + 1),
													maxSize,
													quality,
													widthScale,
													make == "Apple"
												)
												.then((rpp) => {
													resolve(rpp);
												});
										}
									});
								};
							});
						})
					).then((resp) => {
						uni.hideLoading();
						resolve(resp);
					});
				},
				fail: (err) => {
					uni.hideLoading();
					reject();
				},
			});
		});
	},

	toNum(a) {
		a = a.toString();
		let c = a.split(".");
		let num_place = ["", "0", "00", "000", "0000"];
		let r = num_place.reverse();
		for (let i = 0; i < c.length; i++) {
			let len = c[i].length;
			c[i] = r[len] + c[i];
		}
		let res = c.join("");
		return res;
	},

	getImgByteSize(data) {
		if (data && data.graphicContents) {
			// 获取base64图片byte大小
			const equalIndex = data.graphicContents.indexOf("="); // 获取=号下标
			if (equalIndex > 0) {
				const str = data.graphicContents.substring(0, equalIndex); // 去除=号
				data.size = str.length;
			} else {
				const strLength = data.graphicContents.length;
				data.size = strLength;
			}
		} else {
			data.size = null;
		}
	},

	/**
	 * 图片压缩
	 */
	compressImage(
		file,
		fileExtra,
		num,
		quality = 0.3,
		widthScale = 0.8,
		isApple = false
	) {
		return new Promise((resolve, reject) => {
			let img = new Image();
			img.src = file;
			img.onload = function() {
				let newBase64 = ImageScale.compressImage(img, {
					// 压缩质量
					quality: quality,
					mime: "image/jpeg",
					// 压缩时的放大系数，默认为1，如果增大，代表图像的尺寸会变大(最大不会超过原图)
					compressScaleRatio: 1,
					// ios的iPhone下主动放大一定系数以解决分辨率过小的模糊问题
					iphoneFixedRatio: 1,
					// 是否采用原图像素（不会改变大小）
					isUseOriginSize: false,
					// 增加最大宽度，增加后最大不会超过这个宽度
					maxWidth: 0,
					// 使用强制的宽度，如果使用，其它宽高比系数都会失效，默认整图使用这个宽度
					forceWidth: img.width * widthScale,
					// 同上，但是一般不建议设置，因为很可能会改变宽高比导致拉升，特殊场景下使用
					forceHeight: 0,
				});
				resolve(newBase64);
			};
		});
	},

	/**
	 * 预览图片
	 * @param {Object} urls 需要预览的图片链接列表
	 */
	previewImage(urls, current) {
		return new Promise(function(resolve, reject) {
			WX.previewImage({
				urls: urls, // 需要预览的图片链接列表
				current: current, // 当前图片链接
				success: function(res) {
					resolve(true);
				},
				error: function(res) {
					reject(false);
				},
			});
		});
	},

	/**
	 * 获取网络类型
	 * wifi	wifi 网络
	 * 2g	2g 网络
	 * 3g	3g 网络
	 * 4g	4g 网络
	 * ethernet	有线网络	App
	 * unknown	Android 下不常见的网络类型
	 * none	无网络
	 * @param {Object} success
	 * @param {Object} fail
	 */
	getNetworkType() {
		return new Promise(function(resolve, reject) {
			WX.getNetworkType({
				success: function(res) {
					resolve(res.networkType);
				},
				error: function(res) {
					reject(false);
				},
			})
		});
	},

	/**
	 * 拨打电话
	 * @param {Object} phoneNumber
	 */
	makePhoneCall(phoneNumber) {
		return new Promise(function(resolve, reject) {
			uni.makePhoneCall({
				phoneNumber: phoneNumber,
				success: () => {
					resolve(true);
				},
				fail() {
					reject(false);
				},
			});
		});
	},

	/**
	 * 发送短信
	 * @param {Object} telTo 电话号码 ['18611497504', '15811140520']
	 * @param {Object} msgBody 发送内容
	 * @param {Object} success
	 * @param {Object} fail
	 */
	sendMessage(telTo, msgBody, success, fail) {
		return new Promise(function(resolve, reject) {
			let msg = plus.messaging.createMessage(plus.messaging.TYPE_SMS);
			msg.to = telTo;
			msg.body = msgBody;
			plus.messaging.sendMessage(
				msg,
				(res) => {
					resolve(true);
				},
				(e) => {
					reject(false);
				}
			);
		});
	},

	/**
	 * 扫码二者都有
	 */
	scan() {
		return new Promise(function(resolve, reject) {
			WX.scanQRCode({
				desc: "scanQRCode desc",
				needResult: 1, // 默认为0，扫描结果由企业微信处理，1则直接返回扫描结果，
				scanType: ["qrCode", "barCode"], // 可以指定扫二维码还是条形码（一维码），默认二者都有
				success: function(res) {
					// 回调
					let barcode = res.resultStr; // 当needResult为1时返回处理结果
					if (barcode.indexOf("许可证号") >= 0) {
						let start = barcode.indexOf("许可证号") + 5;
						console.log("获取的二维码 start：" + start);
						barcode = barcode.substring(start, start + 12);
						barcode = barcode.replace(/(^\s*)|(\s*$)/g, "");
						console.log("获取的二维码 licCode：" + barcode);
					}
					resolve(barcode);
				},
				error: function(res) {
					if (res.errMsg.indexOf("function_not_exist") > 0) {
						alert("版本过低请升级");
					}
					reject(res.errMsg);
				},
			});
		});
	},
	/**
	 * 调起条码扫描
	 */
	barCode() {
		return new Promise(function(resolve, reject) {
			WX.scanQRCode({
				desc: "scanQRCode desc",
				needResult: 1, // 默认为0，扫描结果由企业微信处理，1则直接返回扫描结果，
				scanType: ["barCode"], // 可以指定扫二维码还是条形码（一维码），默认二者都有
				success: function(res) {
					// 回调
					let barcode = res.resultStr; // 当needResult为1时返回处理结果
					if (barcode.indexOf("许可证号：") >= 0) {
						let start = barcode.indexOf("许可证号：") + 5;
						console.log("获取的二维码 start：" + start);
						barcode = barcode.substring(start, start + 13);
						barcode = barcode.replace(/(^\s*)|(\s*$)/g, "");
						console.log("获取的二维码 licCode：" + barcode);
					}
					resolve(barcode);
				},
				error: function(res) {
					if (res.errMsg.indexOf("function_not_exist") > 0) {
						alert("版本过低请升级");
					}
					reject(res.errMsg);
				},
			});
		});
	},

	/**
	 *  提示框
	 * @param String title 标题
	 * @param String content 提示类容
	 * @param String confirmText 确定按钮文字
	 * @param Boolean showCancel 是否显示取消按钮
	 * @param String cancelText 取消按钮文字
	 * @param {Object} success
	 * @param {Object} fail
	 */
	showModal(
		title,
		content,
		confirmText,
		showCancel,
		cancelText,
		success,
		cancel
	) {
		uni.showModal({
			title: title,
			content: content,
			confirmText: confirmText,
			showCancel: showCancel,
			cancelText: cancelText,
			success: function(res) {
				if (res.confirm) {
					success();
				} else if (res.cancel) {
					cancel();
				}
			},
		});
	},

	/**
	 * 显示操作菜单
	 * @param {Object} title 标题 不需要传：""
	 * @param {Object} actionbuttons 操作菜单 [{title:"不同意",style:"destructive"},{title:"1"},{title:"2"},{title:"3"}]
	 * @param {Object} cancelText 取消按钮文字
	 * @param {Object} success 成功回调
	 */
	showActionSheet(title, actionbuttons, cancelText, success) {
		// #ifdef APP-PLUS
		let actionstyle = {
			title: title,
			cancel: cancelText,
			buttons: actionbuttons,
		};
		plus.nativeUI.actionSheet(actionstyle, function(e) {
			success(e.index - 1);
		});
		// #endif

		// #ifndef APP-PLUS
		let itemList = [];
		for (let i = 0; i < actionbuttons.length; i++) {
			itemList.push(actionbuttons[i].title);
		}
		uni.showActionSheet({
			title: title,
			itemList: itemList,
			cancelText: cancelText,
			success: (e) => {
				console.log(e.tapIndex);
				success(e.tapIndex);
			},
		});
		// #endif
	},

	/**
	 * 获取系统信息
	 */
	getSystemInfo() {
		return new Promise(function(resolve, reject) {
			uni.getSystemInfo({
				success: function(res) {
					let data = {
						brand: res.brand,
						model: res.model,
						pixelRatio: res.pixelRatio,
						screenWidth: res.screenWidth,
						screenHeight: res.screenHeight,
						system: res.system,
						platform: res.platform,
					};
					resolve(data);
				},
				fail(e) {
					reject(e);
				},
			});
		});
	},

	/**
	 *  调起高德 ，百度地图服务
	 * @param {string} route 服务类型 t = 0（驾车）= 1（公交）= 2（步行）= 3（骑行）= 4（火车）= 5（长途客车）
	 * @param {string} dlat 终点纬度
	 * @param {string} dlon 终点经度
	 * @param {string} slat 起点纬度
	 * @param {string} slon 起点经度
	 */
	startNavigation(route, dlat, dlon, slat, slon) {
		return new Promise((resolve, reject) => {
			showActionSheet(
				"选择",
				[{
						title: "高德地图",
					},
					{
						title: "百度地图",
					},
				],
				"取消",
				function(res) {
					let type1 = "";
					console.log("====" + res);
					if (res === 0) {
						type1 = "amap";
					} else if (res === 1) {
						type1 = "baidu";
					}
					startNav(type1);
				}
			);
			// @param {string} type amap- 高德，baidu-百度
			let startNav = function(type) {
				let success = function(result) {
					resolve(result);
				};
				let fail = function(error) {
					reject(error);
				};
				// 判断平台
				if (uni.getSystemInfoSync().platform == "android") {
					// 判断是否是 高德 或者 百度
					if (type == "amap") {
						let uri = "";
						if (slat != undefined && slon != undefined) {
							uri =
								"amapuri://route/plan/?sourceApplication=信用监管&slat=" +
								slat +
								"&slon=" +
								slon +
								"&dlat=" +
								dlat +
								"&dlon=" +
								dlon +
								"&dev=0&t=" +
								route;
						} else {
							uri =
								"amapuri://route/plan/?sourceApplication=信用监管&dlat=" +
								dlat +
								"&dlon=" +
								dlon +
								"&dev=0&t=" +
								route;
						}
						plus.runtime.openURL(encodeURI(uri), function(e) {
							let err = "";
							try {
								err =
									e.indexOf("No Activity found") > -1 ? "未安装高德地图" : e;
							} catch (ep) {
								err = e;
							}
							reject(err);
						});
					} else if (type == "baidu") {
						let uri = "";
						if (slat != undefined && slon != undefined) {
							uri =
								"baidumap://map/direction?origin=" +
								slat +
								"," +
								slon +
								"&destination=" +
								dlat +
								"," +
								dlon +
								"&coord_type=gcj02&mode=" +
								BAIDU_NAV[route] +
								"&src=com.csbi.monopoly.mobile";
						} else {
							uri =
								"baidumap://map/direction?destination=" +
								dlat +
								"," +
								dlon +
								"&coord_type=gcj02&mode=" +
								BAIDU_NAV[route] +
								"&src=com.csbi.monopoly.mobile";
						}
						plus.runtime.openURL(encodeURI(uri), function(e) {
							let err = "";
							try {
								err =
									e.indexOf("No Activity found") > -1 ? "未安装百度地图" : e;
							} catch (ep) {
								err = e;
							}
							reject(err);
						});
					}
				} else if (uni.getSystemInfoSync().platform == "ios") {
					// 判断是否是 高德 或者 百度
					if (type == "amap") {
						let uri = "";
						if (slat != undefined && slon != undefined) {
							uri =
								"iosamap://path/?sourceApplication=信用监管&slat=" +
								slat +
								"&slon=" +
								slon +
								"&dlat=" +
								dlat +
								"&dlon=" +
								dlon +
								"&dev=0&t=" +
								route;
						} else {
							uri =
								"iosamap://path/?sourceApplication=信用监管&dlat=" +
								dlat +
								"&dlon=" +
								dlon +
								"&dev=0&t=" +
								route;
						}
						plus.runtime.openURL(encodeURI(uri), function(e) {
							reject(e);
						});
					} else if (type == "baidu") {
						let uri =
							"baidumap://map/navi?location=" +
							dlat +
							"," +
							dlon +
							"&coord_type=gcj02&mode=" +
							BAIDU_NAV[route] +
							"&type=BLK&src=com.csbi.monopoly.mobile";
						plus.runtime.openURL(encodeURI(uri), function(e) {
							reject(e);
						});
					}
				}
			};
		});
	},
	closeWindow() {
		window.open("about:blank", "_self");
		window.close();
	},

	openLink(url, fileName, size) {
		console.log("previewFile", url);
		WX.invoke("previewFile", {
			url: url,
			name: fileName,
			size: size,
		});
	},

	printWeChat(url, fileName, size) {
		console.log("url", url);
		console.log("fileName", fileName);
		console.log("size", size);
		WX.previewFile({
			url: url, // 需要预览文件的地址(必填，可以使用相对路径)
			name: fileName, // 需要预览文件的文件名(不填的话取url的最后部分)
			size: size, // 需要预览文件的字节大小(必填)
			hidePreviewMenuList: [], // 要隐藏的菜单项，只能隐藏“传播类”和“保护类”按钮，所有menu项见附录3
			showPreviewMenuList: ["previewMenuItem:openWithOtherApp"], // 要显示的菜单项，所有menu项见附录3
		});
	},
};

export default WeChat;